<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-row>
        <el-col :span="17">
          <el-form-item prop="fuzzy">
            <el-input
              v-model="searchForm.fuzzy"
              style="width: 250px"
              placeholder="样品编号/检测因子/采样点位"
            />
          </el-form-item>
          <el-form-item>
            <template>
              <el-button
                type="primary"
                class="iconfont icon-chaxun1"
                size="small"
                @click="handleSearch"
              >
                查询</el-button
              >
            </template>
          </el-form-item>
        </el-col>
        <el-col :span="6" class="search-right">
          <el-button type="text" icon="el-icon-refresh" @click="handleSearch"
            >刷新</el-button
          >
        </el-col>
      </el-row>
    </el-form>

    <div>
      <el-table
        ref="stockTable"
        stripe
        border
        :data="factorData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span> 暂无数据 </span>
            </div>
          </div>
        </template>
        <el-table-column type="index" width="50" align="center" label="序号" />
        <el-table-column
          prop="factorName"
          label="检测因子"
          width="120"
          align="center"
        />
        <el-table-column
          prop="sampleNo"
          label="样品编号"
          width="180"
          align="center"
        />

        <el-table-column
          prop="factorPoint"
          label="采样点位"
          width="120"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="dayAndCount"
          label="频次（次/天）"
          width="130px"
          align="center"
        />
        <el-table-column
          prop="collectTime"
          label="采样时间"
          width="160"
          align="center"
        >
          <template slot-scope="{ row }">
            <template v-if="row.collectTime || row.collectDate">
              {{
                row.collectTime && row.collectTime != ""
                  ? (row.collectDate ? row.collectDate + " " : "") +
                    row.collectTime
                  : row.collectDate
              }}
            </template>
          </template>
        </el-table-column>
        <el-table-column
          prop="standardNo"
          label="标准号"
          width="120"
          align="center"
        />
        <el-table-column
          prop="standardName"
          label="标准名称"
          width="150"
          align="center"
        />
        <el-table-column
          prop="checkRes"
          label="检测结果"
          min-width="150px"
          align="center"
        >
          <template slot-scope="{ row }">
            <template v-if="row.checkRes && row.checkRes.length > 0">
              {{ row.masterRes
              }}<template v-if="row.exponRes !== '' && row.exponRes !== 0"
                >×10<sup>{{ row.exponRes }}</sup></template
              >
              {{
                row.unitName && row.unitName !== "无量纲"
                  ? " " + row.unitName
                  : ""
              }}
            </template>
            <template v-else />
          </template>
        </el-table-column>
        <el-table-column
          prop="assignUser"
          label="分析员"
          width="130"
          align="center"
        />
        <el-table-column
          prop="assayDate"
          label="检测时间"
          width="180"
          align="center"
        />
        <el-table-column fixed="right" align="center" label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetail(scope.row)"
              >修订</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>

    <!-- 修订弹框 -->
    <el-dialog
      title="检测结果修订录入"
      :visible.sync="sampleVisible"
      width="50%"
      center
      top="5vh"
    >
      <el-form
        :model="sampleDetailForm"
        :rules="rules"
        label-width="100px"
        label-position="right"
      >
        <el-card shadow="never">
          <div slot="header" class="clearfix">
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>检测结果信息</span>
          </div>

          <el-row>
            <el-col :span="14">
              <el-form-item label="样品编号:">{{
                sampleDetailForm.sampleNo
              }}</el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="检测因子:">{{
                sampleDetailForm.factorName
              }}</el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="14">
              <el-form-item label="检测标准:">{{
                sampleDetailForm.standardName
              }}</el-form-item>
            </el-col>

            <el-col :span="10">
              <el-form-item label="备注信息:">
                {{ sampleDetailForm.factorRemark }}
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="20">
              <el-form-item label="检测结果:">
                <el-row v-for="(item, index) in subFactorData" :key="index">
                  <el-col
                    :span="4"
                    style="text-align: right;padding-bottom: 5px;"
                  >
                    {{ item.name }}:
                  </el-col>
                  <el-col
                    :span="9"
                    style="margin-left:10px;padding-bottom: 5px;"
                  >
                    <el-input
                      v-model="item.masterRes"
                      type="Number"
                      controls-position="right"
                      :min="0"
                      placeholder="结果值"
                      @change="changeMney(item, index)"
                    >
                      <template slot="append"
                        >E</template
                      >
                    </el-input>
                  </el-col>
                  <el-col
                    :span="9"
                    style="margin-left:10px;padding-bottom: 5px;"
                  >
                    <el-input
                      v-model="item.subRes"
                      type="Number"
                      controls-position="right"
                      :min="0"
                      placeholder="幂数"
                      @change="changeMney(item, index)"
                    >
                      <template v-if="item.unitName" slot="append">{{
                        item.unitName
                      }}</template>
                    </el-input>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="19">
              <el-form-item label="备注:">
                <el-input
                  type="textarea"
                  style="width: 100%;"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  v-model="sampleDetailForm.remark"
                  @change="usernamedata1()"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="19">
              <el-form-item label="检测仪器:">
                <el-row>
                  <el-col :span="8">
                    <el-select
                      v-model="equipmentType"
                      placeholder="仪器分类"
                      style="width: 170px;"
                      @change="handleChangeEqu"
                    >
                      <el-option
                        v-for="(item, index) in level"
                        :key="index"
                        :label="item.name"
                        :value="item.name"
                      />
                    </el-select>
                  </el-col>
                  <el-col :span="8">
                    <el-select
                      v-model="equipmentClass"
                      clearable
                      placeholder="请选择仪器型号"
                      style="width: 170px;"
                      @change="handleChangeEquType"
                    >
                      <el-option
                        v-for="(item, index) in levelTwo"
                        :key="index"
                        :label="item.name"
                        :value="item.name"
                      />
                    </el-select>
                  </el-col>
                  <el-col :span="8">
                    <el-select
                      v-model="equipmentId"
                      clearable
                      placeholder="请选择仪器编号"
                      style="width: 170px;"
                    >
                      <el-option
                        v-for="item in levelThree"
                        :key="item.id"
                        :label="item.equipmentNumber"
                        :value="item.id"
                      />
                    </el-select>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card shadow="never">
          <div slot="header" class="clearfix">
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>修订信息</span>
          </div>

          <el-row>
            <el-col :span="14">
              <el-form-item prop="userName" label="修订人:" label-width="100px">
                <el-input
                  style="width: 240px;"
                  v-model="sampleDetailForm.userName"
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item prop="date" label="修订日期:" label-width="100px">
                <el-date-picker
                  style="width: 240px;"
                  value-format="yyyy-MM-dd"
                  v-model="sampleDetailForm.date"
                  type="date"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item
                prop="checkUser"
                label="审核人:"
                label-width="100px"
              >
                <el-input
                  style="width: 240px;"
                  v-model="sampleDetailForm.checkUser"
                />
              </el-form-item>
            </el-col>

            <el-col :span="10">
              <el-form-item
                prop="checkDate"
                label="审核日期:"
                label-width="100px"
              >
                <el-date-picker
                  style="width: 240px;"
                  value-format="yyyy-MM-dd"
                  v-model="sampleDetailForm.checkDate"
                  type="date"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item prop="reason" label="修订原因:" label-width="100px">
                <el-input
                  type="textarea"
                  style="width: 100%;"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  v-model="sampleDetailForm.reason"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="佐证文件:" prop="file" label-width="110px">
                <el-upload
                  ref="waterImage"
                  class="upload-demo"
                  action="/api/modify/cyFileUpload"
                  :before-remove="beforeRemove"
                  :on-change="customUploadChangeImage2"
                  :before-upload="beforeUpload"
                  :on-exceed="handleExceedImage1"
                  accept=".PDF"
                  name="files"
                  multiple
                  :limit="1"
                  :file-list="fileList"
                >
                  <el-button size="small" type="primary" icon="el-icon-upload2"
                    >点击上传</el-button
                  >
                  <el-button
                    type="primary"
                    size="small"
                    @click.stop="previewFile"
                    >&nbsp;预览文件</el-button
                  >
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sampleVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmCreate">提交</el-button>
      </div>
    </el-dialog>

    <!-- 修订弹框 -->
    <el-dialog
      title="检测结果修订确认"
      :visible.sync="orderDialogVisible"
      center
    >
      <el-form ref="sampleDetailForm" :model="sampleDetailForm">
        <div style="display: flex;">
          <!--动态二级类别信息-->
          <div style="width: 50%;">
            <div class="install-title-1">修改前信息</div>
            <el-card shadow="never">
              <div slot="header" class="clearfix">
                <div
                  style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
                />
                <span>检测结果信息</span>
              </div>

              <el-row>
                <el-col :span="20" v-if="a">
                  <el-form-item label="检测结果:">
                    <el-row v-for="(item, index) in subFactorData" :key="index">
                      <el-col
                        :span="4"
                        style="text-align: right;padding-bottom: 5px;"
                      >
                        {{ item.name }}:
                      </el-col>
                      <el-col
                        :span="7"
                        style="margin-left:10px;padding-bottom: 5px;"
                      >
                        <el-input
                          v-model="originaldata.v1"
                          type="Number"
                          controls-position="right"
                          :min="0"
                          placeholder="结果值"
                          :disabled="true"
                        >
                          <template slot="append"
                            >E</template
                          >
                        </el-input>
                      </el-col>
                      <el-col
                        :span="7"
                        style="margin-left:10px;padding-bottom: 5px;"
                      >
                        <el-input
                          v-model="originaldata.v2"
                          type="Number"
                          controls-position="right"
                          :min="0"
                          placeholder="幂数"
                          :disabled="true"
                        >
                          <template v-if="item.unitName" slot="append">{{
                            item.unitName
                          }}</template>
                        </el-input>
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="20" v-if="b">
                  <el-form-item label="备注:">
                    <el-input
                      type="textarea"
                      style="width: 84%;"
                      :autosize="{ minRows: 2, maxRows: 4 }"
                      v-model="this.oldRemark"
                      :disabled="true"
                    />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="22" v-if="c">
                  <el-form-item label="检测仪器:">
                    <el-row>
                      <el-col :span="6">
                        <el-select
                          v-model="checkdata.equipmentName"
                          placeholder="仪器分类"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="(item, index) in level"
                            :key="index"
                            :label="item.name"
                            :value="item.name"
                          />
                        </el-select>
                      </el-col>
                      <el-col :span="6">
                        <el-select
                          v-model="checkdata.equipmentModel"
                          clearable
                          placeholder="请选择仪器型号"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="(item, index) in levelTwo"
                            :key="index"
                            :label="item.name"
                            :value="item.name"
                          />
                        </el-select>
                      </el-col>
                      <el-col :span="6">
                        <el-select
                          v-model="checkdata.equipmentNumber"
                          clearable
                          placeholder="请选择仪器编号"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="item in levelThree"
                            :key="item.id"
                            :label="item.equipmentNumber"
                            :value="item.id"
                          />
                        </el-select>
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
          </div>

          <div style="width: 30px;"></div>

          <div style="width: 50%;">
            <div class="install-title-1">修改后信息</div>
            <el-card shadow="never">
              <div slot="header" class="clearfix">
                <div
                  style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
                />
                <span>检测结果信息</span>
              </div>

              <el-row>
                <el-col :span="20" v-if="a">
                  <el-form-item label="检测结果:">
                    <el-row v-for="(item, index) in subFactorData" :key="index">
                      <el-col
                        :span="4"
                        style="text-align: right;padding-bottom: 5px;"
                      >
                        {{ item.name }}:
                      </el-col>
                      <el-col
                        :span="7"
                        style="margin-left:10px;padding-bottom: 5px;"
                      >
                        <el-input
                          v-model="item.masterRes"
                          type="Number"
                          controls-position="right"
                          :min="0"
                          placeholder="结果值"
                          :disabled="true"
                        >
                          <template slot="append"
                            >E</template
                          >
                        </el-input>
                      </el-col>
                      <el-col
                        :span="7"
                        style="margin-left:10px;padding-bottom: 5px;"
                      >
                        <el-input
                          v-model="item.subRes"
                          type="Number"
                          controls-position="right"
                          :min="0"
                          placeholder="幂数"
                          :disabled="true"
                        >
                          <template v-if="item.unitName" slot="append">{{
                            item.unitName
                          }}</template>
                        </el-input>
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="20" v-if="b">
                  <el-form-item label="备注:">
                    <el-input
                      type="textarea"
                      style="width: 84%;"
                      :autosize="{ minRows: 2, maxRows: 4 }"
                      v-model="sampleDetailForm.remark"
                      :disabled="true"
                    />
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="22" v-if="c">
                  <el-form-item label="检测仪器:">
                    <el-row>
                      <el-col :span="6">
                        <el-select
                          v-model="equipmentType"
                          placeholder="仪器分类"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="(item, index) in level"
                            :key="index"
                            :label="item.name"
                            :value="item.name"
                          />
                        </el-select>
                      </el-col>
                      <el-col :span="6">
                        <el-select
                          v-model="equipmentClass"
                          clearable
                          placeholder="请选择仪器型号"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="(item, index) in levelTwo"
                            :key="index"
                            :label="item.name"
                            :value="item.name"
                          />
                        </el-select>
                      </el-col>
                      <el-col :span="6">
                        <el-select
                          v-model="equipmentId"
                          clearable
                          placeholder="请选择仪器编号"
                          style="width: 140px;"
                          :disabled="true"
                        >
                          <el-option
                            v-for="item in levelThree"
                            :key="item.id"
                            :label="item.equipmentNumber"
                            :value="item.id"
                          />
                        </el-select>
                      </el-col>
                    </el-row>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
          </div>
        </div>

        <el-card shadow="never" style="margin-top: 30px;">
          <div slot="header">
            <span>修订信息<i class="el-input__icon"/></span>
          </div>

          <el-row>
            <el-col :span="4">
              <el-form-item prop="userName" label="修订人:" label-width="110px">
                {{ this.sampleDetailForm.userName }}
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item prop="date" label="修订日期:" label-width="110px">
                {{ this.sampleDetailForm.date }}
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item
                prop="checkUser"
                label="审核人:"
                label-width="110px"
              >
                {{ this.sampleDetailForm.checkUser }}
              </el-form-item>
            </el-col>

            <el-col :span="5">
              <el-form-item
                prop="checkDate"
                label="审核日期:"
                label-width="110px"
              >
                {{ this.sampleDetailForm.checkDate }}
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item
                prop="checkUser"
                label="修订原因:"
                label-width="110px"
              >
                {{ this.sampleDetailForm.reason }}
              </el-form-item>
            </el-col>
          </el-row>
                    <el-row>
            <el-col :span="12">
              <el-form-item label="佐证文件:" prop="file" label-width="110px">
                <el-upload
                  ref="waterImage"
                  class="upload-demo"
                  action="/api/modify/cyFileUpload"
                  :before-remove="beforeRemove"
                  :on-change="customUploadChangeImage2"
                  :before-upload="beforeUpload"
                  :on-exceed="handleExceedImage1"
                  accept=".PDF"
                  name="files"
                  multiple
                  :limit="1"
                  :file-list="fileList"
                >
                  <!-- <el-button size="small" type="primary" icon="el-icon-upload2"
                    >点击上传</el-button
                  > -->
                  <el-button
                    type="primary"
                    size="small"
                    @click.stop="previewFile"
                    >&nbsp;预览文件</el-button
                  >
                </el-upload>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="orderDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmCreateVisible">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as retesting from "@/api/retesting";
import { laboratoryEquipmentTree } from "@/api/equipment";
import Pagination from "@/components/Pagination"; // Secondary package based on el-pagination

export default {
  components: {
    Pagination
  },
  data() {
    return {
      searchForm: {
        pageNumber: 1,
        pageSize: 10
      },
      factorData: [],
      total: 0,
      selection: [],
      SelectionDrawUser: [],
      multiplese: [],
      sampleVisible: false,
      orderDialogVisible: false,
      currentSample: "",
      sampleImage: "",
      sampleImageList: [],
      multipleSelection: [],
      factorMultipleSelection: [],
      sampleDataInfo: [],
      sampleSecInfo: {},
      sampleSecInfodata: [],
      sampledata: [],
        checkRes: "",

      //数据
      sampleDetailForm: {
        checkFactorId: "",
        checkRes: "",
        checkSubRes: "",
        remark: ""
      },
      sampleDetailFormdata:{},
      params: [],
      modify: [],
      original: [],

      sampleNo: "",

      fileList: [],
      arrManufacturer: true,
      baseUrl: this.$store.getters.sysBaseUrl + "/cyImg/",

      subFactorData: [],
      equipmentType: "",
      equipmentClass: "",
      equipmentId: "",
      level: [],
      levelTwo: [],
      levelThree: [],
      oldRemark: "",
      originaldata: "",
      checkdata: "",
      a: false,
      b: false,
      c: false,
      rules: {
        userName: [
          { required: true, message: "修订人不能为空", trigger: "blur" }
        ],
        checkUser: [
          { required: true, message: "审核人不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.handleSearch();
    this.getEquipment();
  },
  methods: {
    handleSearch() {
      this.searchForm.id = this.$route.query.id;
      retesting.checkFactors(this.searchForm).then(res => {
        if (res.code === 200) {
          this.factorData =
            res.result.records.map(i => {
              if (i.checkRes && i.checkRes !== "") {
                const ob = JSON.parse(i.checkRes);
                this.$set(i, "masterRes", ob.v1);
                this.$set(i, "exponRes", ob.v2);
              } else {
                this.$set(i, "masterRes", 0);
                this.$set(i, "exponRes", 0);
              }
              return i;
            }) || [];
          this.total = res.result.total;
        }
      });
    },
    getEquipment() {
      this.level = [];
      this.levelTwo = [];
      this.levelThree = [];
      laboratoryEquipmentTree().then(res => {
        if (res.result) {
          const treeData = res.result ? res.result : [];
          if (treeData !== "") {
            this.level = treeData;
          }
        }
      });
    },
    //修订
    handleDetail(row) {
      console.log(row);
      console.log(this.sampleDetailForm.isFactor);

      (this.fileList = []),
        // 获取数据
        (this.sampleDetailForm = { ...row });
      let data = JSON.parse(JSON.stringify({ ...row }));
      this.sampleDetailFormdata = data;
      this.subFactorData = [];
      if (row.factorSubsetVos && row.factorSubsetVos.length > 0) {
        this.subFactorData = row.factorSubsetVos.map(m => {
          const subO = JSON.parse(m.checkSubRes);
          return {
            id: m.id,
            name: m.factorName,
            masterRes: subO ? subO.v1 : "",
            subRes: subO ? subO.v2 : "",
            unitName: m.unitName
          };
        });
      } else {
        const resObj = JSON.parse(row.checkRes);
        this.subFactorData = [
          {
            name: row.factorName,
            masterRes: resObj ? resObj.v1 : "",
            subRes: resObj ? resObj.v2 : "",
            unitName: row.unitName
          }
        ];
      }
      this.equipmentType = "";
      this.equipmentClass = "";
      this.equipmentId = "";
      const equObj = JSON.parse(row.checkEquipment);
      if (equObj) {
        this.equipmentType = equObj.equipmentName;
        this.equipmentClass = equObj.equipmentModel;
        this.equipmentId = equObj.equipmentNumber;
        // this.equipmentId = equObj.id
        // this.handleChangeEqu(equObj.equipmentName)
        // this.handleChangeEquType(equObj.equipmentModel)
      }

      this.sampleVisible = true;
    },

    handleChangeEqu(val) {
      this.equipmentClass = [];
      this.equipmentId = [];
      this.levelTwo = [];
      this.levelThree = [];
      const o = this.level.find(i => i.name === val);
      if (o) {
        this.levelTwo = o.children || [];
      }
      this.c = true;
    },
    handleChangeEquType(val) {
      this.equipmentId = [];
      this.levelThree = [];
      const o = this.levelTwo.find(i => i.name === val);
      if (o) {
        this.levelThree = o.children || [];
      }
      this.c = true;
    },

    // 检测结果修改后触发
    changeMney() {
      this.a = true;
      this.original = this.sampleDetailForm.checkRes;
      this.originaldata = JSON.parse(this.original);
      console.log(this.originaldata);
    },
    // 备注修改后触发
    usernamedata1() {
      this.b = true;
      this.oldRemark = this.sampleDetailFormdata.remark;
      console.log(this.oldRemark);
    },

    // 附件上传图片预览事件，这个就是将路径直接放进一个弹窗显示出来就可以了

    handlePictureCardPreview(file) {
      console.log(file);
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },

    beforeUpload(e) {
      // console.log(e);
      this.files = e;
    },

    customUploadChangeImage2(files) {
      console.log(files);
      if (files.status === "ready") return;
      if (files.status === "success") {
        const res = files.response || {};
        if (res && res.code === 200) {
          let url = files.response.result;
          // let urlStr = url.lastIndexOf("/");
          // let fileName = url.substr(urlStr + 1);
          console.log(url);
          this.sampleDetailForm.file = url;
          console.log(this.sampleDetailForm.file);

          this.$message({
            type: "success",
            message: "上传成功!"
          });
        } else {
          this.$message.error("上传失败!");
          this.fileList = [];
        }
      } else {
        this.$message.error("上传失败!");
        this.fileList = [];
      }
    },

    // 删除文件
    beforeRemove(files, fileList) {
      return this.$confirm(`确定移除 ${files.name}？`);
    },

    handleExceedImage1(file, fileList) {
      // console.log(file);
      this.$message.warning(`当前限制上传 1 个文件，以上传 ${file.length} 个`);
    },

    //预览文件
    previewFile() {
      if (
        this.sampleDetailForm.file != undefined &&
        this.sampleDetailForm.file != ""
      ) {
        var url =
          "https://www.huancelian.com/cyImg/" + this.sampleDetailForm.file;
        window.open(url);
      } else {
        this.$message.warning(`请上传文件`);
      }
    },

    confirmCreate() {
      this.checkdata = JSON.parse(this.sampleDetailForm.checkEquipment);
      this.orderDialogVisible = true;
    },
    confirmCreateVisible() {
      const equipmentInfo = this.levelThree.find(
        i => i.id === this.equipmentId
      );

      let data;
      if (this.sampleDetailForm.isFactor === "0") {
        // 正常因子
        const checkResInfo = {
          name: this.subFactorData[0].name,
          v1: this.subFactorData[0].masterRes,
          v2: this.subFactorData[0].subRes
        };
        if (this.original.length != 0) {
          this.modify = JSON.stringify(checkResInfo);
        } else {
          this.original = "";
          this.modify = "";
        }
        data = {
          checkFactorId: this.sampleDetailForm.checkFactorId,
          checkRes: JSON.stringify(checkResInfo),
          original: [this.original],
          modify: [this.modify],
          remark: this.sampleDetailForm.remark,
          oldRemark: this.oldRemark,
          checkEquipment: JSON.stringify(equipmentInfo),
          oldCheckEquipment: this.sampleDetailForm.checkEquipment,
          userName: this.sampleDetailForm.userName,
          date: this.sampleDetailForm.date,
          checkUser: this.sampleDetailForm.checkUser,
          checkDate: this.sampleDetailForm.checkDate,
          reason: this.sampleDetailForm.reason,
          file: this.sampleDetailForm.file
        };
      } else {
        const checkResInfo = this.subFactorData.map(i => {
          const resInfo = {
            name: i.name,
            v1: i.masterRes,
            v2: i.subRes
          };
          return {
            id: i.id,
            unitName: i.unitName,
            checkSubRes: JSON.stringify(resInfo)
          };
        });
        data = {
          checkFactorId: this.sampleDetailForm.checkFactorId,
          original: [this.original],
          modify: [this.modify],
          factorSubsetVos: checkResInfo,
          remark: this.sampleDetailForm.remark,
          oldRemark: this.oldRemark,
          checkEquipment: JSON.stringify(equipmentInfo),
          oldCheckEquipment: this.sampleDetailForm.checkEquipment,
          userName: this.sampleDetailForm.userName,
          date: this.sampleDetailForm.date,
          checkUser: this.sampleDetailForm.checkUser,
          checkDate: this.sampleDetailForm.checkDate,
          reason: this.sampleDetailForm.reason,
          file: this.sampleDetailForm.file
        };
      }
      retesting.modifydata(data).then(res => {
        if (res.code === 200) {
          console.log(res.code);
          this.$notify({
            title: "成功",
            message: res.message,
            type: "success"
          });
          this.original = "";
          this.handleSearch();
          this.sampleVisible = false;
          this.orderDialogVisible = false;
        } else {
          this.$notify({
            title: "失败",
            message: res.message,
            type: "error"
          });
          this.original = "";
          this.handleSearch();
          this.sampleVisible = false;
          this.orderDialogVisible = false;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-upload--picture-card {
  background-color: #fbfdff;
  border: 0px dashed #c0ccda;
  border-radius: 12px;
  box-sizing: border-box;
  width: 30px;
  height: 30px;
  cursor: pointer;
  line-height: 40px;
  vertical-align: top;
}
::v-deep .el-upload-list {
  display: flex;
  margin: 5px;
  width: 140%;
  li {
    height: 80%;
    margin: 0;
  }
}
.search_div {
  > div {
    &:nth-child(1) {
      margin-right: 10px;
    }
    display: inline-block;
  }
}

.search_input {
  width: 200px;
  margin-bottom: 5px;
}
.search-right {
  text-align: right;
  padding-right: 25px;
}
.item {
  font-size: 16px;
}
::v-deep .el-card .el-card__header {
  padding: 5px 20px;
  background: #f3f2f2;
}
.block-flex {
  position: relative;
  display: flex;
  & > div {
    border: 1px solid #b7b7b7;
    width: 100px;
    margin: 0;
    line-height: 30px;
    text-align: center;
  }
  & > div:first-child {
    background: #b7b7b7;
  }
}
.card-left {
  width: 100%;
  min-height: 200px;
  max-height: 450px;
}
.card-right {
  width: 100%;
  min-height: 200px;
  max-height: 450px;
}
.el-card {
  overflow: auto;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 14px;
}
// /deep/.main-body .el-table__header-wrapper  .el-checkbox{
//   display:none
// }
.agreement_picture {
  min-height: calc(100%);
  .pdf {
    height: calc(100%);
  }
}

/deep/ .el-input.is-disabled .el-input__inner {
  color: unset;
}

/deep/.i-input .el-input__inner {
  text-align: center;
}
/deep/.right-input .el-input__inner {
  text-align: right;
}

.el-header {
  line-height: 45px;
  height: 45px;
}
.el-footer {
  text-align: right;
  line-height: 45px;
  height: 45px;

  .pagination-container {
    padding: 0;
    margin-top: 10px;
    margin-bottom: 45px;
  }
}
.el-main {
  overflow-y: auto;
}
.el-container {
  max-height: 450px;
}

.text {
  font-size: 14px;
}
.dialog-item {
  padding-left: 3px;
  line-height: 30px;
  cursor: pointer;
}
.dialog-item:hover {
  background: #e8f4ff;
  border-radius: 3px;
}

table {
  background-color: transparent;
}

caption {
  padding-top: 8px;
  padding-bottom: 8px;
  color: #777;
  text-align: left;
}

th {
  text-align: left;
}

.table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 20px;
}

.table > tbody > tr > td,
.table > tbody > tr > th,
.table > tfoot > tr > td,
.table > tfoot > tr > th,
.table > thead > tr > td,
.table > thead > tr > th {
  padding: 8px;
  line-height: 1.42857143;
  vertical-align: middle;
  border-top: 1px solid #ddd;
}

.table > thead > tr > th {
  vertical-align: bottom;
  border-bottom: 2px solid #ddd;
}

.table > caption + thead > tr:first-child > td,
.table > caption + thead > tr:first-child > th,
.table > colgroup + thead > tr:first-child > td,
.table > colgroup + thead > tr:first-child > th,
.table > thead:first-child > tr:first-child > td,
.table > thead:first-child > tr:first-child > th {
  border-left: 1px solid #f1f2f4;
}

.table > tbody + tbody {
  border-top: 2px solid #ddd;
}

.table .table {
  background-color: #ffffff;
}

.table-condensed > tbody > tr > td,
.table-condensed > tbody > tr > th,
.table-condensed > tfoot > tr > td,
.table-condensed > tfoot > tr > th,
.table-condensed > thead > tr > td,
.table-condensed > thead > tr > th {
  padding: 5px;
}

.table-bordered {
  border: 1px solid #ddd;
}

.table-bordered > tbody > tr > td,
.table-bordered > tbody > tr > th,
.table-bordered > tfoot > tr > td,
.table-bordered > tfoot > tr > th,
.table-bordered > thead > tr > td,
.table-bordered > thead > tr > th {
  border: 1px solid #ddd;
}

.table-bordered > thead > tr > td,
.table-bordered > thead > tr > th {
  border-bottom-width: 2px;
}

.table-striped > tbody > tr:nth-of-type(odd) {
  background-color: #f9f9f9;
}

.table-hover > tbody > tr:hover {
  background-color: #f5f5f5;
}

table col[class*="col-"] {
  position: static;
  display: table-column;
  float: none;
}

table td[class*="col-"],
table th[class*="col-"] {
  position: static;
  display: table-cell;
  float: none;
}

.table > tbody > tr.active > td,
.table > tbody > tr.active > th,
.table > tbody > tr > td.active,
.table > tbody > tr > th.active,
.table > tfoot > tr.active > td,
.table > tfoot > tr.active > th,
.table > tfoot > tr > td.active,
.table > tfoot > tr > th.active,
.table > thead > tr.active > td,
.table > thead > tr.active > th,
.table > thead > tr > td.active,
.table > thead > tr > th.active {
  background-color: #f5f5f5;
}

.table-hover > tbody > tr.active:hover > td,
.table-hover > tbody > tr.active:hover > th,
.table-hover > tbody > tr:hover > .active,
.table-hover > tbody > tr > td.active:hover,
.table-hover > tbody > tr > th.active:hover {
  background-color: #e8e8e8;
}

.table > tbody > tr.success > td,
.table > tbody > tr.success > th,
.table > tbody > tr > td.success,
.table > tbody > tr > th.success,
.table > tfoot > tr.success > td,
.table > tfoot > tr.success > th,
.table > tfoot > tr > td.success,
.table > tfoot > tr > th.success,
.table > thead > tr.success > td,
.table > thead > tr.success > th,
.table > thead > tr > td.success,
.table > thead > tr > th.success {
  background-color: #dff0d8;
}

.table-hover > tbody > tr.success:hover > td,
.table-hover > tbody > tr.success:hover > th,
.table-hover > tbody > tr:hover > .success,
.table-hover > tbody > tr > td.success:hover,
.table-hover > tbody > tr > th.success:hover {
  background-color: #d0e9c6;
}

.table > tbody > tr.info > td,
.table > tbody > tr.info > th,
.table > tbody > tr > td.info,
.table > tbody > tr > th.info,
.table > tfoot > tr.info > td,
.table > tfoot > tr.info > th,
.table > tfoot > tr > td.info,
.table > tfoot > tr > th.info,
.table > thead > tr.info > td,
.table > thead > tr.info > th,
.table > thead > tr > td.info,
.table > thead > tr > th.info {
  background-color: #d9edf7;
}

.table-hover > tbody > tr.info:hover > td,
.table-hover > tbody > tr.info:hover > th,
.table-hover > tbody > tr:hover > .info,
.table-hover > tbody > tr > td.info:hover,
.table-hover > tbody > tr > th.info:hover {
  background-color: #c4e3f3;
}

.table > tbody > tr.warning > td,
.table > tbody > tr.warning > th,
.table > tbody > tr > td.warning,
.table > tbody > tr > th.warning,
.table > tfoot > tr.warning > td,
.table > tfoot > tr.warning > th,
.table > tfoot > tr > td.warning,
.table > tfoot > tr > th.warning,
.table > thead > tr.warning > td,
.table > thead > tr.warning > th,
.table > thead > tr > td.warning,
.table > thead > tr > th.warning {
  background-color: #fcf8e3;
}

.table-hover > tbody > tr.warning:hover > td,
.table-hover > tbody > tr.warning:hover > th,
.table-hover > tbody > tr:hover > .warning,
.table-hover > tbody > tr > td.warning:hover,
.table-hover > tbody > tr > th.warning:hover {
  background-color: #faf2cc;
}

.table > tbody > tr.danger > td,
.table > tbody > tr.danger > th,
.table > tbody > tr > td.danger,
.table > tbody > tr > th.danger,
.table > tfoot > tr.danger > td,
.table > tfoot > tr.danger > th,
.table > tfoot > tr > td.danger,
.table > tfoot > tr > th.danger,
.table > thead > tr.danger > td,
.table > thead > tr.danger > th,
.table > thead > tr > td.danger,
.table > thead > tr > th.danger {
  background-color: #f2dede;
}

.table-hover > tbody > tr.danger:hover > td,
.table-hover > tbody > tr.danger:hover > th,
.table-hover > tbody > tr:hover > .danger,
.table-hover > tbody > tr > td.danger:hover,
.table-hover > tbody > tr > th.danger:hover {
  background-color: #ebcccc;
}

.table-responsive {
  min-height: 3.01%;
  overflow-x: auto;
}

.table-bordered,
.table-bordered > tbody > tr > td,
.table-bordered > tbody > tr > th,
.table-bordered > tfoot > tr > td,
.table-bordered > tfoot > tr > th,
.table-bordered > thead > tr > td,
.table-bordered > thead > tr > th {
  border: 1px solid #e9ecef;
  text-align: center;
  line-height: 14px;
}

.table-bordered,
td,
th {
  border-radius: 0 !important;
}

.table-bordered > tbody > tr:last-child > td {
  border-bottom: 1px solid #e9ecef;
}

.bootstrap-table .fixed-table-container .fixed-table-header {
  overflow: hidden;
  background: rgba(0, 0, 0, 0.05);
}

.fixed-table-header .table > thead > tr {
  background: none !important;
}

.table > thead > tr {
  color: #636363;
  font-weight: 400;
  background: rgba(0, 0, 0, 0.05);
  /*   background: repeat-x #fafafa;
  background-image: -webkit-linear-gradient(top,#F8F8F8 0,#fafafa 100%);
  background-image: -o-linear-gradient(top,#F8F8F8 0,#fafafa 100%);
  background-image: linear-gradient(to bottom,#F8F8F8 0,#fafafa 100%);
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff8f8f8', endColorstr='#ffececec', GradientType=0); */
}

.table > thead > tr > th {
  border-color: #e9ecef;
  font-weight: 700;
  border-right-color: transparent;
}

.table > thead > tr > th .ace-icon:first-child {
  margin-right: 2px;
}

.table > thead > tr > th:first-child {
  border-left-color: #f1f1f1;
}

.table > thead > tr > th:last-child {
  border-right-color: #f1f1f1;
}

.table.table-bordered > thead > tr > th {
  vertical-align: middle;
}

td.center,
th.center {
  text-align: center;
}

td .lbl,
th .lbl {
  margin-bottom: 0;
}

td .lbl:only-child,
th .lbl:only-child {
  vertical-align: top;
}

.table-header {
  background-color: #307ecc;
  color: #fff;
  font-size: 14px;
  line-height: 38px;
  padding-left: 12px;
  margin-bottom: 1px;
}

.table-header .close {
  margin-right: 8px;
  margin-top: 0;
  opacity: 0.45;
  filter: alpha(opacity=45);
}

.table-header .close:hover {
  opacity: 0.75;
  filter: alpha(opacity=75);
}

th.detail-col {
  width: 48px;
  text-align: center;
}

tr.detail-row {
  display: none;
}

tr.detail-row.open {
  display: block;
  display: table-row;
}

tr.detail-row > td {
  background-color: #f1f6f8;
  border-top: 3px solid #d1e1ea !important;
}

.table-detail {
  background-color: #fff;
  border: 1px solid #dcebf7;
  width: 100%;
  padding: 12px;
}

.table-detail td > .profile-user-info {
  width: 100%;
}
.clearfix {
  line-height: 40px;
  display: flex;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.install-title {
  display: flex;
  align-items: center;
  line-height: 30px;
  padding-left: 20px;
  color: #0a0a0a;
  background-color: #e1e1e3;
  justify-content: flex-start;
  margin-bottom: 10px;
}
.install-title-1 {
  display: flex;
  align-items: center;
  line-height: 30px;
  padding-left: 20px;
  color: #0a0a0a;
  background-color: #e2f0ff;
  justify-content: flex-start;
  margin-bottom: 10px;
}
.delete {
  width: 10px;
  height: 10px;
  position: relative;
  top: -10px;
  cursor: pointer;
}
::v-deep.el-upload-list__item {
  margin: 10px 10px;
}
::v-deep.el-upload-list--picture .el-upload-list__item {
  margin: 10px 10px !important;
}
.user-info-head {
  position: relative;
  display: inline-block;
  height: 120px;
}

::v-deep.avatar-upload-preview {
  width: 400px;
  border-radius: 0%;
  height: 400px;
  > img {
    transform: translateX(0);
  }
}
.user-info-head:hover:after {
  content: "+";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  color: #eee;
  background: rgba(0, 0, 0, 0.5);
  font-size: 24px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: pointer;
  line-height: 110px;
  border-radius: 50%;
}

/deep/.upload-dragger {
  background-color: #fff;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.cropper-wrapper {
  //height: calc(100vh - 50px);
  .pre-box {
    button {
      width: 100px;
      margin-top: 15px;
    }
  }
}

/deep/.el-dialog {
  position: relative;
  margin: 0 auto 50px;
  background: #fff;
  border-radius: 2px;
  box-sizing: border-box;
  width: 80%;
}

.crop-dialog {
  .cropper-content {
    padding: 0 40px;

    .cropper {
      width: 900px;
      height: 900px;
    }
  }

  .action-box {
    padding: 25px 40px 0 40px;
    display: flex;
    justify-content: center;

    button {
      width: 80px;
      margin-right: 15px;
    }
  }

  .dialog-footer {
    button {
      width: 100px;
    }
  }
}
</style>
